package com.szqhyxj.youxiangju.sys.components.view.popview;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.szqhyxj.youxiangju.R;

public abstract class BasePopView implements View.OnClickListener {
    protected Activity activity;
    public View popView;
    public PopupWindow pop;
    protected LayoutInflater inflater;

    public BasePopView(Activity activity) {
        this.activity = activity;
        inflater = LayoutInflater.from(activity);
        popView = initPopView(inflater);
    }

    protected abstract View initPopView(LayoutInflater inflater);

    // 显示选择图片的popview
    public void showPopView() {
        pop = new PopupWindow(popView, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        pop.setFocusable(true);
        pop.setOutsideTouchable(true);
        pop.setAnimationStyle(R.style.pop_anim_up_down);
//        ColorDrawable dw = new ColorDrawable(0xb0000000);
        ColorDrawable dw = new ColorDrawable(activity.getResources().getColor(android.R.color.transparent));
        dw.setAlpha(150);
        // 设置SelectPicPopupWindow弹出窗体的背景
        pop.setBackgroundDrawable(dw);

        if (pop.isShowing()) {
            return;
        }
        pop.showAtLocation(activity.getWindow().getDecorView(), Gravity.RIGHT
                | Gravity.BOTTOM, 0, 0);


    }

    public void dismiss() {
        if (pop != null && pop.isShowing()) {
            pop.dismiss();
            pop = null;
        }
    }

}